package edu.gatech.cs2340.mule.tests;

import static org.junit.Assert.*;

import java.awt.Color;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import edu.gatech.cs2340.mule.model.Player;
import edu.gatech.cs2340.mule.model.Race;
import edu.gatech.cs2340.mule.model.RandomEvent;

/**
 * This JUnit file tests the RandomEvent class. Most specifically, the
 * updatePlayer() method.
 * 
 * @author Zach Elliott
 *
 */
public class RandomEventTest {

	Player player;
	RandomEvent random;
	
	@Before
	public void setUp() throws Exception {
		//create a Player to apply the RandomEvent to
		player = new Player(Color.RED, "Badluck Brian", new Race("Human"));
		
		//create new RandomEvent object
		random = new RandomEvent(player, 1);
	}
	
	@Test
	public void noBadEventToLastPlaceTest() {
		player.setInLast(true);
		for(int i = 0; i < 4; i++) { //run 4 times to get each expected value of index
			random = new RandomEvent(player,1);
			Assert.assertTrue(random.getEventIndex()<4);
		}
		
		player.setInLast(false);
		for(int i = 0; i < 7; i++) { //run 7 times to get each expected value of index
			random = new RandomEvent(player,1);
			Assert.assertTrue(random.getEventIndex()<7);
		}
	}
	
	@Test
	public void event0Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		
		random.updatePlayer(player,0,0); //round number doesn't matter, input 0 arbitrarily
		
		Assert.assertEquals(player.getFoodAmount(),3);
		Assert.assertEquals(player.getEnergyAmount(),2);
	}
	
	@Test
	public void event1Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		
		random.updatePlayer(player,1,0); //round number doesn't matter, input 0 arbitrarily
		
		Assert.assertEquals(player.getSmithOreAmount(),2);
	}

	@Test
	public void event2Round1Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setMoneyAmount(2000);
		
		random.updatePlayer(player,2,1);
		
		Assert.assertEquals(player.getMoneyAmount(),2200);
	}
	
	@Test
	public void event2Round4Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setMoneyAmount(2000);
		
		random.updatePlayer(player,2,4);
		
		Assert.assertEquals(player.getMoneyAmount(),2400);
	}
	
	@Test
	public void event2Round8Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setMoneyAmount(2000);
		
		random.updatePlayer(player,2,8);
		
		Assert.assertEquals(player.getMoneyAmount(),2600);
	}
	
	@Test
	public void event2Round12Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setMoneyAmount(2000);
		
		random.updatePlayer(player,2,12);
		
		Assert.assertEquals(player.getMoneyAmount(),2800);
	}
	
	@Test
	public void event3Round1Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setMoneyAmount(2000);
		
		random.updatePlayer(player,3,1);
		
		Assert.assertEquals(player.getMoneyAmount(),2050);
	}
	
	@Test
	public void event3Round4Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setMoneyAmount(2000);
		
		random.updatePlayer(player,3,4);
		
		Assert.assertEquals(player.getMoneyAmount(),2100);
	}
	
	@Test
	public void event3Round8Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setMoneyAmount(2000);
		
		random.updatePlayer(player,3,8);
		
		Assert.assertEquals(player.getMoneyAmount(),2150);
	}
	
	@Test
	public void event3Round12Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setMoneyAmount(2000);
		
		random.updatePlayer(player,3,12);
		
		Assert.assertEquals(player.getMoneyAmount(),2200);
	}
	
	@Test
	public void event4Round1Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setMoneyAmount(2000);
		
		random.updatePlayer(player,4,1);
		
		Assert.assertEquals(player.getMoneyAmount(),1900);
	}
	
	@Test
	public void event4Round4Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setMoneyAmount(2000);
		
		random.updatePlayer(player,4,4);
		
		Assert.assertEquals(player.getMoneyAmount(),1800);
	}
	
	@Test
	public void event4Round8Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setMoneyAmount(2000);
		
		random.updatePlayer(player,4,8);
		
		Assert.assertEquals(player.getMoneyAmount(),1700);
	}
	
	@Test
	public void event4Round12Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setMoneyAmount(2000);
		
		random.updatePlayer(player,4,12);
		
		Assert.assertEquals(player.getMoneyAmount(),1600);
	}
	
	@Test
	public void event5Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setFoodAmount(10);
		
		random.updatePlayer(player,5,0); //round number doesn't matter, input 0 arbitrarily
		
		Assert.assertEquals(player.getFoodAmount(),5);
	}
	
	@Test
	public void event6Round1Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setMoneyAmount(2000);
		
		random.updatePlayer(player,6,1);
		
		Assert.assertEquals(player.getMoneyAmount(),1850);
	}
	
	@Test
	public void event6Round4Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setMoneyAmount(2000);
		
		random.updatePlayer(player,6,4);
		
		Assert.assertEquals(player.getMoneyAmount(),1700);
	}
	
	@Test
	public void event6Round8Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setMoneyAmount(2000);
		
		random.updatePlayer(player,6,8);
		
		Assert.assertEquals(player.getMoneyAmount(),1550);
	}
	
	@Test
	public void event6Round12Test() {
		player.setFoodAmount(-50);		//zero out food
		player.setEnergyAmount(-50);	//zero out energy
		player.setSmithOreAmount(-50);	//zero out smithore
		player.setMoneyAmount(-10000);	// zero out money
		player.setMoneyAmount(2000);
		
		random.updatePlayer(player,6,12);
		
		Assert.assertEquals(player.getMoneyAmount(),1400);
	}
}
